package com.test

import java.sql.DriverManager

import org.apache.spark.rdd.JdbcRDD
import org.apache.spark.{SparkConf, SparkContext}

object TestDemo1 {
  def main(args: Array[String]): Unit = {
    val conf=new SparkConf();
    conf.setMaster("local[*]")
    conf.setAppName("get")
    val sc=new SparkContext(conf)
    val driver="com.mysql.jdbc.Driver";
    val url="jdbc:mysql://localhost:3306/bank"
    val username="root"
    val password="bq020526"
    val rdd=new JdbcRDD(
      sc,()=>{
        Class.forName(driver)
        DriverManager.getConnection(url,username,password)
      },
      "select * from tb_customer",2,20,3,
      result=>(result.getInt(1),result.getString(2))
    )
    rdd.collect.foreach(println)
  }

}
